package com.itheima.leyou.controller;

import com.itheima.leyou.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@Configuration
public class ClientController {

    @Resource
    private ClientService clientService;

    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }

    @Autowired
    RestTemplate restTemplate;

    @RequestMapping(value = "/getTime")
    @ResponseBody
    public String getTime(){
        return restTemplate.getForObject("http://leyou-time-server/getTime", String.class);
    }

    /**
     * 通过输入count，模拟操作
     * @param count
     * @return
     */
    @RequestMapping(value = "/test/{type}/{count}/{content}")
    @ResponseBody
    public String test(@PathVariable("type") int type, @PathVariable("count") int count, @PathVariable("content") String content){
        return clientService.test(type, count, content);
    }
}
